// Copyright 2008 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview Default renderer for {@link goog.ui.TabBar}s.  Based on the
 * original {@code TabPane} code.
 *
 * @author attila@google.com (Attila Bodis)
 * @author eae@google.com (Emil A. Eklund)
 */

goog.provide('mp.ui.GLayoutRenderer');

goog.require('goog.dom.a11y.Role');
goog.require('goog.ui.ContainerRenderer');



/**
 * Default renderer for {@link goog.ui.TabBar}s, based on the {@code TabPane}
 * code.  The tab bar's DOM structure is determined by its orientation and
 * location relative to tab contents.  For example, a horizontal tab bar
 * located above tab contents looks like this:
 * <pre>
 *   <div class="goog-tab-bar goog-tab-bar-horizontal goog-tab-bar-top">
 *     ...(tabs here)...
 *   </div>
 * </pre>
 * @constructor
 * @extends {goog.ui.ContainerRenderer}
 */
mp.ui.GLayoutRenderer = function() {
  goog.base(this);
};
goog.inherits(mp.ui.GLayoutRenderer, goog.ui.ContainerRenderer);
goog.addSingletonGetter(mp.ui.GLayoutRenderer);


/**
 * Default CSS class to be applied to the root element of components rendered
 * by this renderer.
 * @type {string}
 */
mp.ui.GLayoutRenderer.CSS_CLASS = goog.getCssName('mp-glayout');


/**
 * Returns the CSS class name to be applied to the root element of all tab bars
 * rendered or decorated using this renderer.
 * @return {string} Renderer-specific CSS class name.
 * @override
 */
mp.ui.GLayoutRenderer.prototype.getCssClass = function() {
  return mp.ui.GLayoutRenderer.CSS_CLASS;
};


/**
 * Returns the ARIA role to be applied to the tab bar element.
 * See http://wiki/Main/ARIA for more info.
 * @return {goog.dom.a11y.Role} ARIA role.
 * @override
 */
mp.ui.GLayoutRenderer.prototype.getAriaRole = function() {
  return undefined; //goog.dom.a11y.Role.GRID;
};

/** @override */
mp.ui.GLayoutRenderer.prototype.createDom = function(control) {
  var element = control.getElement();
  return element;
}


/**
 * Sets the tab bar's state based on the given CSS class name, encountered
 * during decoration.  Overrides the superclass implementation by recognizing
 * class names representing tab bar orientation and location.
 * @param {goog.ui.Container} control Tab bar to configure.
 * @param {string} className CSS class name.
 * @param {string} baseClass Base class name used as the root of state-specific
 *     class names (typically the renderer's own class name).
 * @protected
 * @override
 */
mp.ui.GLayoutRenderer.prototype.setStateFromClassName = function(control,
    className, baseClass) {
    goog.base(this, 'setStateFromClassName', control, className, baseClass);
};


/**
 * Returns all CSS class names applicable to the tab bar, based on its state.
 * Overrides the superclass implementation by appending the location-specific
 * class name to the list.
 * @param {goog.ui.Container} tabBar Tab bar whose CSS classes are to be
 *     returned.
 * @return {Array.<string>} Array of CSS class names applicable to the tab bar.
 * @override
 */
mp.ui.GLayoutRenderer.prototype.getClassNames = function(control) {
  var classNames = goog.base(this, 'getClassNames', control);
  return classNames;
};
